package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeeDTO;
import com.sky.entity.Category;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类管理")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /*
     * 修改
     * */
    @ApiOperation("修改分类")
    @PutMapping()
    public Result ModifyPagination(@RequestBody CategoryDTO categoryDTO) {

        categoryService.ModifyPagination(categoryDTO);

        return Result.success();
    }

    /*
     * 分页查询
     * */
    @ApiOperation("分类分页+条件查询")
    @GetMapping("/page")
    public Result<PageResult> PagingQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.PagingQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /*
     * 启用，禁用
     * */
    @ApiOperation("分类禁用，启用")
    @PostMapping("/status/{status}")
    public Result Enabledisable(@PathVariable Integer status, Integer id) {
        categoryService.Enabledisable(status, id);
        return Result.success();
    }

    /*
     *新增
     *
     * */
    @ApiOperation("分类新增")
    @PostMapping()
    public Result save(@RequestBody CategoryDTO categoryDTO) {
        categoryService.save(categoryDTO);
        return Result.success();
    }

    /*
     * 根据id删除
     * */
    @ApiOperation("分类根据id删除")
    @DeleteMapping()
    public Result Delecategory(Long id) {
        categoryService.Delecategory(id);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
